<template>
  <div class="tabbar">
    <ul>
      <li
        v-for="(item, index) in routerList"
        :key="index"
        @click="switchTab(item.parth)"
      >
        <img
          :src="$route.path === item.parth ? item.selected : item.active"
          alt=""
        />
        <span :class="$route.path === item.parth ? 'active' : ''">{{
          item.title
        }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
//require
export default {
  name: "tabbaar",
  data() {
    return {
      routerList: [
        {
          title: "首页",
          parth: "/home",
          // active:"../../assets/image/home.png",
          active: require("@/assets/image/home.png"),
          selected: require("@/assets/image/home-select.png"),
        },
        {
          title: "分类",
          parth: "/list",
          active: require("@/assets/image/list.png"),
          selected: require("@/assets/image/list-select.png"),
        },
        {
          title: "购物车",
          parth: "/cart",
          active: require("@/assets/image/cart.png"),
          selected: require("@/assets/image/cart-select.png"),
        },
        {
          title: "我的",
          parth: "/my",
          active: require("@/assets/image/my.png"),
          selected: require("@/assets/image/my-select.png"),
        },
      ],
    };
  },
  methods: {
    switchTab(path) {
      //判断是否点击了同一个路由
      if (this.$route.path === path) return;
      //跳转对应页面
      this.$router.replace(path);
    },
  },
};
</script>

<style scoped lang="less">
.tabbar {
 position: fixed;
 left:0;
 bottom: 0;
  width: 100%;
  height: 1.5rem;
  background-color: #fff;

  ul {
    display: flex;
    justify-content: space-around;
    align-self: center;
    width: 100%;
    height: 100%;

    li {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      img {
        width: 0.8rem;
        height: 0.8rem;
      }
      span {
        font-size: 0.2rem;
      }
      .active {
        color: #d00;
      }
    }
  }
}
</style>
